/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package miselania.tiposgenericos;
import java.util.*;


/**
 *
 * @author UNSAAC73
 */
public class PruebaTiposGenericosPregunta3 {
   Iterator iterador;
/*
    static void listar(LinkedList lista, Iterator iterador){
        
        
        while (iterador.hasNext()){
        System.out.print(iterador.next()+" ");  
  }
  System.out.println();
    }
    public static void main(String[] args) {
  System.out.println("Ejemplo de listas enlazadas!");
  LinkedList <Integer>list = new LinkedList<Integer>();
  int num1 = 11, num2 = 22, num3 = 33, num4 = 44;
  int size;
  Iterator iterador;
  //Adding data in the list
  list.add(num1);
  list.add(num2);
  list.add(num3);
  list.add(num4);
  size = list.size();
  System.out.print( "DAtos de la lista enlazada ");  
  //Create a iterator
  iterador = list.iterator(); 
  listar(list,iterador);
  //Check list empty or not
  if (list.isEmpty()){
  System.out.println("Linked list is empty");
  }
  else{
  System.out.println( "Linked list size: " + size);
  }
  System.out.println("Adding data at 1st location: 55");
  //Adding first
  list.addFirst(55);
  System.out.print("Now the list contain: ");
  iterador = list.iterator();
  while (iterador.hasNext()){
  System.out.print(iterador.next()+" ");  
  }
  System.out.println();
  System.out.println("Now the size of list: " + list.size());
  System.out.println("Adding data at last location: 66");
  //Adding last or append
  list.addLast(66);
  System.out.print("Now the list contain: ");
  iterador = list.iterator();
  listar(list,iterador);
  System.out.println();
  System.out.println("Now the size of list: " + list.size());
  System.out.println("Adding data at 3rd location: 55");
  //Adding data at 3rd position
  list.add(2,99);
  System.out.print("Now the list contain: ");
  iterador = list.iterator();
 listar(list,iterador);
  System.out.println();
  System.out.println("Now the size of list: " + list.size());
  //Retrieve first data
  System.out.println("First data: " + list.getFirst());
  //Retrieve lst data
  System.out.println("Last data: " + list.getLast());
  //Retrieve specific data
  System.out.println("Data at 4th position: " + list.get(3));
  //Remove first
  int first = list.removeFirst();
  System.out.println("Data removed from 1st location: " + first);
  System.out.print("Now the list contain: ");
  iterador = list.iterator();
  //After removing data
  listar(list,iterador);
  System.out.println();
  System.out.println("Now the size of list: " + list.size());
  //Remove last
  int last = list.removeLast();
  System.out.println("Data removed from last location: " + last);
  System.out.print("Now the list contain: ");
  iterador = list.iterator();
  //After removing data
 listar(list,iterador);
  System.out.println();
  System.out.println("Now the size of list: " + list.size());
  //Remove 2nd data
  int second = list.remove(1);
  System.out.println("Data removed from 2nd location: " + second);
  System.out.print("Now the list contain: ");
  iterador = list.iterator();
  //After removing data
 listar(list,iterador);
  System.out.println();
  System.out.println("Now the size of list: " + list.size());
  //Remove all
  list.clear();
  if (list.isEmpty()){
  System.out.println("Linked list is empty");
  }
  else{
  System.out.println( "Linked list size: " + size);
  }
    System.out.println( "--------------#####################-------------------");
     miLinkedList l= new miLinkedList();
     l.agregar("aa", null);
     l.agregar("j", last);
  }*/
    
   public static void main( String[] args){
       miLinkedList <String> listaEnlazada = new miLinkedList <String>();
       listaEnlazada.agregar("primer");
       listaEnlazada.agregar("Segundo");
        System.out.println(listaEnlazada.contador);
       System.out.println("listado enlazado de  dos elementos \n"+ listaEnlazada.toString());
       listaEnlazada.agregar("tercero");
       System.out.println("Si agregamos un tercer elemento \n");
       System.out.println("el listado enlazado de  tres elementos \n"+ listaEnlazada.toString());
       
       System.out.println("ahora eliminamos el elemento Segundo \n");
       
       if(!listaEnlazada.borrar("Segundo"))
           System.out.println("elemento no encontrado");
       else
          System.out.println("elemento eliminado"); 
       
       System.out.println("Asi queda la list enlazada\n");
       System.out.println("listado enlazado final \n"+ listaEnlazada.toString());
                System.out.println("---------------------------");
         System.out.println("ahora eliminamos el elemento Cuarto (no existente) \n");
       
       if(!listaEnlazada.borrar("Cuarto"))
           System.out.println("elemento no encontrado");
       else
          System.out.println("elemento eliminado"); 
       
       System.out.println("Asi queda la list enlazada\n");
       System.out.println("listado enlazado final \n"+ listaEnlazada.toString());
          
       
           
   }
    
}
